package other.barcode.test;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author bingo
 * @Description
 * @Date 2018/7/24
 */
public class BlockingQueueDemo {
    public static void main(String[] args) {
        BlockingQueue blockingQueue = new LinkedBlockingQueue();
        new Thread(){
            @Override
            public void run() {
                try {
                    while (true) {
                        String code = blockingQueue.take().toString();
                        System.out.println("code=" + code);
                    }

                } catch(InterruptedException e){
                        e.printStackTrace();
                }

            }
        }.start();
        new Thread(){

            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                blockingQueue.add("11");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                blockingQueue.add("22");


            }
        }.start();
    }
}
